// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import './data.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(title: const Text('这是列表页面')),
      body: const MyText(),
    ),
  ));
}

// 在屏幕上画一个盒子，宽度是屏幕的宽度，高度是宽度的一半
class MyText1 extends StatelessWidget {
  const MyText1({super.key});
  @override
  Widget build(BuildContext context) {
    return AspectRatio(
        aspectRatio: 2 / 1,
        child: Container(
          color: Colors.red,
        ));
  }
}

// Card组件的使用
class MyText2 extends StatelessWidget {
  const MyText2({super.key});
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Card(
          // color: Colors.amber,
          // 阴影的深度
          elevation: 10,
          // 设置阴影的深度
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
          shadowColor: Colors.red,
          margin: const EdgeInsets.all(10),
          child: const Column(children: [
            ListTile(
              title: Text('张三'),
              subtitle: Text('高级软件工程师'),
            ),
            Divider(),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            ),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            )
          ]),
        ),
        const Card(
          child: Column(children: [
            ListTile(
              title: Text('张三'),
              subtitle: Text('高级软件工程师'),
            ),
            Divider(),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            ),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            )
          ]),
        ),
        const Card(
          child: Column(children: [
            ListTile(
              title: Text('张三'),
              subtitle: Text('高级软件工程师'),
            ),
            Divider(),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            ),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            )
          ]),
        ),
        const Card(
          child: Column(children: [
            ListTile(
              title: Text('张三'),
              subtitle: Text('高级软件工程师'),
            ),
            Divider(),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            ),
            ListTile(
              title: Text('电话'),
              trailing: Text('17340540900'),
            )
          ]),
        )
      ],
    );
  }
}

// 使用Card实现图文列表 ClipOval, CircleAvator实现圆角图片
class MyText3 extends StatelessWidget {
  const MyText3({super.key});
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Card(
          // 阴影颜色
          shadowColor: Colors.blue,
          // 阴影的长度
          elevation: 10,
          // 圆角
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          child: Column(
            children: [
              Image.network(
                'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLDEYWBo9eGlSzicLOsiaewkzPicaPtpIVtvUKekSF6icdxLRb4bBImYzcPEQFaRFVaBTFjibO5WIN9PVg/132',
                height: 150,
                width: double.infinity,
                fit: BoxFit.cover,
              ),
              // Row(
              //   children: [
              //     Image.network(
              //       'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLDEYWBo9eGlSzicLOsiaewkzPicaPtpIVtvUKekSF6icdxLRb4bBImYzcPEQFaRFVaBTFjibO5WIN9PVg/132',
              //       width: 80,
              //       height: 80,
              //     ),
              //     const SizedBox(
              //       height: 80,
              //       child: Column(
              //         children: [
              //           Expanded(
              //               flex: 1,
              //               child: Text(
              //                 '这是文案这是文案这是文文案这是文案',
              //                 style: TextStyle(),
              //               )),
              //           Text('哈哈哈'),
              //         ],
              //       ),
              //     )
              //   ],
              // )
              ListTile(
                leading: ClipOval(
                  child: Image.network(
                    'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLDEYWBo9eGlSzicLOsiaewkzPicaPtpIVtvUKekSF6icdxLRb4bBImYzcPEQFaRFVaBTFjibO5WIN9PVg/132',
                    fit: BoxFit.cover,
                  ),
                ),
                title: const Text('这是标题'),
                subtitle: const Text('这个是副标题---'),
              )
            ],
          ),
        ),
        Card(
          // 阴影颜色
          shadowColor: Colors.blue,
          // 阴影的长度
          elevation: 10,
          // 圆角
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          child: Column(
            children: [
              Image.network(
                'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLDEYWBo9eGlSzicLOsiaewkzPicaPtpIVtvUKekSF6icdxLRb4bBImYzcPEQFaRFVaBTFjibO5WIN9PVg/132',
                height: 150,
                width: double.infinity,
                fit: BoxFit.cover,
              ),
              const ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLDEYWBo9eGlSzicLOsiaewkzPicaPtpIVtvUKekSF6icdxLRb4bBImYzcPEQFaRFVaBTFjibO5WIN9PVg/132'),
                ),
                title: Text('这是标题'),
                subtitle: Text('这个是副标题---'),
              )
            ],
          ),
        )
      ],
    );
  }
}

class MyText extends StatelessWidget {
  const MyText({super.key});

  List<Widget> _initRender() {
    List<Widget> tempList = [];
    for (var k = 0; k < listData.length; k++) {
      tempList.add(Card(
        // 阴影颜色
        shadowColor: Colors.blue,
        // 阴影的长度
        elevation: 10,
        // 圆角
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
        child: Column(
          children: [
            Image.network(
              listData[k]['avator'],
              height: 150,
              width: double.infinity,
              fit: BoxFit.cover,
            ),
            ListTile(
              leading: CircleAvatar(
                backgroundImage: NetworkImage(listData[k]['avator']),
              ),
              title: Text(listData[k]['content']),
              subtitle: Text(listData[k]['subContent']),
            )
          ],
        ),
      ));
    }
    return tempList;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: _initRender(),
    );
  }
}
